package com.stu;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalINIConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.IOException;

/**
 * @author MI
 * @ClassName ConfigCRUD.java
 * @createTime 2021年10月28日 15:55:00
 */
public class ConfigCRUD {
    @Test
    public void read() {
        try {
            File file = new ClassPathResource("my.ini").getFile();

            HierarchicalINIConfiguration iniConfiguration = new HierarchicalINIConfiguration(file);
            String string = iniConfiguration.getSection("default").getString("url");
            //读取
            iniConfiguration.getSection("default").setProperty("url", StringUtils.repeat(string, 2));
            System.out.println(string);
            //更新
            iniConfiguration.save();

        } catch (ConfigurationException | IOException e) {
            e.printStackTrace();
        }
    }
}
